<template>
    <div class="pages borderbox pl10 pr10">
        <div class="bold fs18 h44 lh44">{{title}}</div>
        <ul class="flex flexWrap lists flexJCB">
            <li :class="(index%2==0?'lfs':'rfs')+'flex col textL p10 lis'"
                v-for="(item,index) in discountData" :key="index"
                @click.stop="toNext('categoryDetail',{cateNo:item.productNo})">
                <img class="imgs" :src="item.coverPicUrl" />
                <p class="fs14 mt5 mb5 h36 lh18 w100 ofh ml3">{{item.productName | sliceString(16)}}</p>
                <span class="price flex flexSpaceB ml3">
                    <span><span class="fs12">￥</span>{{item.salePrice}}</span>
                    <span class="flex flexCenter pl10 pr10 pt3 pb3 bgR" @click.stop="addShopCart(item)">
                        <img src="../../../images/cart2@2x.png" class="mr2 h10 w10" alt="">
                        <span class="fs12 ml2 lh12 mt3">添加</span>
                    </span>
                </span>
            </li>
        </ul>
    </div>
</template>
<script>
import mixins,{ isRegPhoneNumber } from 'mixins';
import { Shopset } from 'request';
import { Toast } from "mint-ui";
export default {
    name:'discountGoods',
    mixins:[mixins,isRegPhoneNumber],
    props:{
        discountList:{
            default:()=>[],
        },
        title:{
            default:'优惠商品',
        }
    },
    computed:{
        discountData(){
            if(this.discountList.length != 0){
                return this.discountList;
            }
            return this.$store.state.d.noContentGoods;
        }
    },
    created(){

    },
    methods:{
        addShopCart(val){
            Shopset({
                productNo: val.productNo,
                isAdd:'01',
                buynum: 1,
                specIds: val.specIds || '',
                selectBox:'true',
            }).then(res=>{
                if(res.rspCode == '0000' && res.data.code == '0000'){
                    this.$Toast()
                    this.$emit('funCB') 
                    this.show = false;
                }else{
                    Toast({ message:'添加购物车失败',position:'middle',duration:1500});
                }
            }).catch(err=>console.log(err));
        }
    }
}
</script>
<style lang="less" scoped>
.pages{
    &>div{
        background:url('../../../images/bg23.png') no-repeat center center;
    }
    .imgs{
        width:100%;
        border-radius: .5rem;
    }
    .price{
        color:#ff3932;
    }
    .lists{
        align-content:space-between;
        box-sizing:border-box;
        margin-bottom:.4rem;
        .lis{
            box-sizing:border-box;
            width:48%;
            background:white;
            border-radius:.7rem;
            margin-bottom:.7rem;
        }
        .lfs{
            margin-left:2%;
        }
        .rfs{
            margin-right:2%;
        }
    }
    .bgR{
        border-radius: 1rem;
        background:#f0eff5;
    }
}
</style>
